﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

public class CsvToDataTable
{
    public static DataTable Load(string filePath)
    {
        DataTable returnTable = new DataTable();

        string[] lines = System.IO.File.ReadAllLines(filePath);

        string topLine = lines[0];
        string[] columnNames = topLine.Split(',');

        foreach (string columnName in columnNames)
        {
            returnTable.Columns.Add(columnName);
        }

        for (int row = 1; row < lines.Length; row++)
        {
            DataRow newRow = returnTable.NewRow();
            string[] rowValues = lines[row].Split(',');
            for (int column = 0; column < returnTable.Columns.Count; column++)
            {
                newRow[column] = rowValues[column];
            }
            returnTable.Rows.Add(newRow);
        }

        return returnTable;

    }
}
